# https://blog.csdn.net/oqqENvY12/article/details/103276462

import torch
import torchvision

# An instance of your model.
model = torchvision.models.resnet34(pretrained=True)# 这样就导入了resnet50的预训练模型了

# Must add this line, or there would be BUG, like the output index not right
model.eval()

# An example input you would normally provide to your model's forward() method.
example = torch.rand(1, 3, 224, 224)
  
print("example:",example)
# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.
traced_script_module = torch.jit.trace(model, example) # 您可以获取现有模块或python函数，提供示例输入，然后运行该函数，记录在所有张量上执行的操
traced_script_module.save("take_traced_resnet_model.pt")



# with torch.no_grad():
#print("with torch.no_grad():")
#output = traced_script_module(torch.ones(1, 3, 224, 224))
#
#print(output[0, :5])
 







